import Vue from 'vue'
import Vuex from 'vuex'
import {
  getStores,
  getRegion
} from 'api'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    id:'',
    stores:[],
    region:[]
  },
  mutations: {
    SET_USER_ID(state,id){
      state.id = id
    },
    SET_STORES(state,stores){
      state.stores = stores
    },
    SET_REGION(state,stores){
      state.region = stores
    },
  },
  actions: {
    async GetStores({commit}){
      let res = await getStores()
      commit('SET_STORES',res.results)
      return res
    },
    async GetRegion({commit}){
      let res = await getRegion()
      commit('SET_REGION',res)
    },
  },
  getters: {
    stores: state => state.stores,
    region: state => state.region
  }
})
